package Test;

/**
 * @author 连安利
 * @version 1.0
 * @date 2021/3/18 19:49
 */
public class test02 {

    public static void main(String[] args) {
        int a[] = {1,1,3,4,1,5};
        System.out.println(findMaxButtons(a));
    }

    public static long findMaxButtons (int[] buttons) {

        // write code here
        long sum=0;
        int n = buttons.length;

        for(int i= 1; i<=n; i++){
            if(buttons[i-1] == 0){
                break;
            }
            if(buttons[i-1] == 1){
                sum = sum + 1;
                continue;
            }
            sum = sum+1;
            sum = sum+i*(buttons[i-1]-1);
        }
        return sum;
    }
}
